package com.ict.txmsv2.services;

import com.ict.txmsv2.mapper.LendMapper;
import com.ict.txmsv2.model.Equipment;
import com.ict.txmsv2.model.Lend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yoleen
 * @date 2020/12/20 12:29
 */

@Service
public class LendService {
    @Autowired
    LendMapper lendMapper;

    @Autowired
    EquipService equipService;

    public List<Lend> getAllLend(String lName, String lTime, Integer status, String returnTime) {
        return lendMapper.getAllLend(lName,lTime,status,returnTime);
    }

    public int addLend(Lend lend) {
        return lendMapper.insertSelective(lend);
    }

    public int updateLend(Lend lend) {
        if (lend.getStatus() == 2 || lend.getStatus() == 3) {
            Equipment equipment = new Equipment();
            equipment.setId(lend.getEid());
            equipment.setStatus(lend.getStatus());
            equipService.updateEquip(equipment);
        }
        return lendMapper.updateByPrimaryKeySelective(lend);
    }
}
